package com.jstyle.jclifexd.daoManager;




import com.jstyle.jclifexd.dao.PhoneRecordDao;
import com.jstyle.jclifexd.model.PhoneRecord;
import com.jstyle.jclifexd.utils.DbManager;

import org.greenrobot.greendao.query.QueryBuilder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/4/10.
 */

public class PhoneRecordDaoManager {


    public static void insertPathRecord(PhoneRecord PhoneRecord){
        DbManager.getInstance().getDaoSession().getPhoneRecordDao().insert(PhoneRecord);
    }
    public static void insertPathRecord(List<PhoneRecord>pathRecordList){
        DbManager.getInstance().getDaoSession().getPhoneRecordDao().insertOrReplaceInTx(pathRecordList);
    }

    public static PhoneRecord getPathRecord(String date){
        PhoneRecordDao pathRecordDao=DbManager.getInstance().getDaoSession().getPhoneRecordDao();
        QueryBuilder<PhoneRecord> builder = pathRecordDao.queryBuilder();
        builder.where(PhoneRecordDao.Properties.Time.eq(date));
        return builder.unique();
    }
    public static List<PhoneRecord> getPathRecord(String startDate, String endDate){
        List<PhoneRecord> hrvDataList=new ArrayList<>();
        QueryBuilder<PhoneRecord> queryBuilder= DbManager.getInstance().getDaoSession().getPhoneRecordDao().queryBuilder();
        hrvDataList= queryBuilder.where(PhoneRecordDao.Properties.Time.between(startDate,endDate)).orderAsc(PhoneRecordDao.Properties.Time).list();
        return hrvDataList;
    }
    public static List<PhoneRecord> getPathRecordData(String startDate, String endDate){
        List<PhoneRecord> hrvDataList=new ArrayList<>();
        QueryBuilder<PhoneRecord> queryBuilder= DbManager.getInstance().getDaoSession().getPhoneRecordDao().queryBuilder();
        hrvDataList= queryBuilder.where(PhoneRecordDao.Properties.Time.between(startDate,endDate)).orderAsc(PhoneRecordDao.Properties.Time).list();
        return hrvDataList;
    }
    public static List<PhoneRecord> getAllPathRecord(){
        PhoneRecordDao pathRecordDao=DbManager.getInstance().getDaoSession().getPhoneRecordDao();
        QueryBuilder<PhoneRecord> builder = pathRecordDao.queryBuilder().orderDesc(PhoneRecordDao.Properties.Time);
        return builder.list();
    }


    public static void deleteAll(){
        DbManager.getInstance().getDaoSession().getPhoneRecordDao().deleteAll();;
    }
}
